#ifndef LONGKEY_COMMON_CGI_H_
#define LONGKEY_COMMON_CGI_H_

#include <tchar.h>

class CGI {
public:
	// Maximum factor by which EscapeString() can increase the string length
	static const int kEscapeFactor = 3;

	// EscapeString() converts funky characters found in "src[0,srcn-1]" into
	// escape sequences.  The escaped string is placed back in "dst".  At most
	// "dstn" characters are written into "dst", including the
	// null-termination byte.  Returns true if
	// successful, false if the escaped string will not fit entirely in "dstn"
	// characters.  Since escaping can increase the length, "dst" should not
	// be the same as "src".

	// These functions always return a null-terminated string, even if they
	// fail (e.g. if a bad escape sequence is found).  As a consequence, you
	// must pass in a dstn > 0.
	// If you want to guarantee that the result will fit, you need
	//      dstn >= kEscapeFactor * srcn + 1
	// for EscapeString and
	//      dstn >= srcn + 1
	// for UnescapeString.

	static bool EscapeString(const TCHAR* src, int srcn, TCHAR* dst, int dstn);
	static bool UnescapeString(const TCHAR* src, int srcn, TCHAR* dst, int dstn);
};

#endif	// LONGKEY_COMMON_CGI_H_